package com.gxa.zhonglong.service.impl;

import com.gxa.zhonglong.mapper.HeadquartersMapper;
import com.gxa.zhonglong.mapper.InventoryMapper;
import com.gxa.zhonglong.pojo.Inventory;
import com.gxa.zhonglong.pojo.WarehouseWarrant;
import com.gxa.zhonglong.pojo.Where;
import com.gxa.zhonglong.service.InventoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.util.*;

@Service
public class InventoryServiceImp implements InventoryService {

    @Autowired
    InventoryMapper inventoryMapper = null;


    @Autowired
    HeadquartersMapper headquartersMapper = null;

    public void timeToStand(List<Map<String,Object>> list){
        for (int i = 0; i < list.size(); i++) {
            Map map = list.get(i);
            System.out.println(map);
            Set set = ((HashMap) map).keySet();
            Iterator iterator = set.iterator();
            while (iterator.hasNext()) {
                String key = iterator.next().toString();
                Object o = ((HashMap) map).get(key);
                if (o instanceof Timestamp) {
                    ((HashMap) map).put(key,o.toString());
                }
            }
        }
    }


    @Override
    public void insertInventory(Inventory inventory) {

        inventoryMapper.insertInventory(inventory);
    }

    @Override
    public List<Map<String, Object>> selectByReceiptNumberInventory(String receiptNumber) {

        List<Map<String, Object>> maps = inventoryMapper.selectByReceiptNumberInventory(receiptNumber);
        return maps;
    }

    @Override
    public List<Map<String,Object>> selectByWhere(Where where) {
        Integer page = where.getPage();
        Integer size = where.getSize();
        where.setPage((page-1)*size);
        List<Map<String, Object>> selectByWhere = inventoryMapper.selectByWhere(where);

        timeToStand(selectByWhere);

        return selectByWhere;
    }

    @Override
    public List<Map<String, Object>> selectByWhereNoPage(Where where) {
        List<Map<String, Object>> selectByWhere = inventoryMapper.selectByWhere(where);
        timeToStand(selectByWhere);
        return selectByWhere;
    }

    @Override
    public void updateByReceiptNumber(Inventory inventory) {
       inventoryMapper.updateByReceiptNumber(inventory);
    }

    @Override
    public List<Map<String, Object>> selectByReceiptNumberGoods(String receiptNumber) {
        List<Map<String, Object>> maps = inventoryMapper.selectByReceiptNumberGoods(receiptNumber);
        return maps;
    }

    @Override
    public void deleteByReceiptNumberInventory(String receiptNumber) {
        inventoryMapper.deleteByReceiptNumberInventory(receiptNumber);
    }





}
